package cn.telling.product.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cn.telling.product.dao.IDirectionalDao;
import cn.telling.product.dao.INoDirectionalDao;
import cn.telling.product.service.INoDirectionalService;
import cn.telling.product.vo.AreaInfoVo;

/**
 * 
 * @ClassName: NoDirectionalServiceImpl 
 * @Description: 产品非定向发布业务服务接口的实现
 * @author 陈赟 
 * @date 2015年6月18日 上午11:25:33 
 *
 */
@Service("noDirectionalService")
public class NoDirectionalServiceImpl implements INoDirectionalService {
	@Autowired
	@Qualifier("noDirectionalDao")
	private INoDirectionalDao noDirectionalDao;
	
	@Autowired
    @Qualifier("directionalDao")
    private IDirectionalDao directionalDao;
	
	/**保存非定向数据*/
	@Override
	@Transactional(value = "txManager", isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, rollbackFor = { Exception.class })
	public int insertNoDirectional(String shopProductId,String priceretailonline,String shareCode, String stockNumber,String areaId,String userId,String isShare, String gifts, String isContainInvoice,String pkStore) {
		int supplyArea0Id = noDirectionalDao.insertNoDirectional(shopProductId, priceretailonline, shareCode, stockNumber, areaId, userId, isShare, gifts, isContainInvoice,pkStore);
		return supplyArea0Id;
	}
	
	/**根据areaId、areaLevel 查询 市级区域Id 列表*/
	@Override
	public List<String> getAreaIdListByAreaLevel(String areaId, String areaLevel) {
		List<String> areaIdList = new ArrayList<String>();
		
		List<AreaInfoVo> areaInfoVoList = directionalDao.getAreaLsByAreaId(areaId, areaLevel);
		if(areaInfoVoList != null && areaInfoVoList.size() > 0){
			for (int i = 0; i < areaInfoVoList.size(); i++) {
				areaIdList.add(areaInfoVoList.get(i).getAreaId().toString());
			}
		}
		
		if(areaIdList != null && areaIdList.size() > 0){
			return areaIdList;
		}
		return null;
	}
}